<?php

namespace App\Modules\User\Models;

use Illuminate\Database\Eloquent\Model;
use DB;

class User extends Model
{
    protected $tables = 'users';

    protected $fillable = ['id','openid','nickname','avatar','gender','phone','from_type','vip','balance','name','birth_at','papers_type','papers','height','weight','created_at','updated_at','is_agree_protoc','status','jg_token','login_device','user_agent','jg_register_id'];



    static function getUserInfo($uid)
    {
        $info = self::where('id',$uid)->first();
        return $info;
    }
    
    static function getUserInfoArr($uid)
    {
    	$info = self::where('id',$uid)->first()->toArray();
    	return $info;
    }


    static function addOrUpdate($param){
        $user = self::firstOrCreate($param);
        return $user;
    }

    static function findByPhone($phone) {
        return self::where('phone',$phone)->first();
    }

    static function updateUser($param)
    {
        // TODO check
        return self::where('id',$param['id'])->update($param);
    }

}